from sklearn.datasets import load_iris
import numpy as np
import pandas as pd       #pandas库数据类型为dataframe
import matplotlib.pyplot as plt
import seaborn as sns

iris_flower = load_iris()
# print(iris_flower)
# print(iris_flower.keys())
# print(iris_flower.values())


# 1.特征
# print(iris_flower['data'])
# print(np.shape(iris_flower['data']))
# features = (iris_flower['feature_names'])
# print(features)
# # print(np.shape(iris_flower['']))

# # # 2.标签

# print(iris_flower['target'])
# print(np.shape(iris_flower["target"]))
# print(iris_flower['target_names'])
# # print(iris_flower.values())

# 3.深入观察
# target = iris_flower['target']
# features = iris_flower['data']
# # 算均值
# # print(type(features[:,0]))     #第一个为列，第二个为行
# # print("计算特征矩阵第一列的均值：",np.mean(features[:,0]))
# print(features.mean(axis = 0)) #均值
# print(features.var(axis = 0))  #方差
# print(features.std(axis = 0))  #标准差
# print(features.max(axis = 0))  #最大值 
# print(features.min(axis = 0))  #最小值
# print(features.mean(axis = 0))

flowers = pd.DataFrame(data=iris_flower['data'],columns = iris_flower['feature_names'])       #将numpy的数据类型转化成pandas的数据类型
# # flowers["target"] = iris_flower['target']
print(flowers)
# print(flowers.describe())




#数据图形化表达
#1.分析数据的分布特征
#target
# plt.hist(target)                            #折线图
# plt.show()
# features_0 = features[:,0]
# plt.scatter(features_0)                   #散点图
#2.分析各列数据的相关性

r_matrix = flowers.corr()
# print(r_matrix)
fig, ax = plt.subplots(figsize=(10, 10))  # 创建一个新的图形和坐标轴，设置图形大小为10x10 
sns.heatmap(r_matrix, annot=True, cmap='coolwarm', linewidths=.5, ax=ax)  # 绘制相关性矩阵的热图  

plt.show()  # 显示图形